<template>
  <div class="app-container">
    <!--工具栏-->
    <div class="head-container">
      <div v-if="crud.props.searchToggle">
        <el-input
          v-model="query.name"
          placeholder="请输入业务流程名称"
          clearable
          size="small"
          style="width: 200px;"
          class="filter-item"
          @keyup.enter.native="toQuery"
        />
        <rrOperation :crud="crud" />
      </div>
      <crudOperation show="" :permission="permission" />

    </div>
    <el-table
      ref="table"
      v-loading="crud.loading"
      style="width: 100%;"
      :data="crud.data"
      @filter-change="crud.handleFilterChange"
      @select="crud.selectChange"
      @select-all="crud.selectAllChange"
      @selection-change="crud.selectionChangeHandler"
    >
      <el-table-column type="selection" width="55" />
      <el-table-column v-if="columns.visible('processName')" prop="processName" label="业务流程名称" />
      <el-table-column v-if="columns.visible('projectId')" prop="projectId" label="项目ID" />
      <el-table-column v-if="columns.visible('identifier')" prop="identifier" label="项目空间" />
      <el-table-column v-if="columns.visible('description')" prop="description" label="描述" />
    </el-table>
    <pagination :total="2" />
    <!-- 新增页面 -->
    <el-dialog
      append-to-body
      :close-on-click-modal="false"
      :before-close="closeDialog"
      :visible.sync="crud.status.cu > 0"
      title="新增业务流程"
      width="1200px"
      top="5vh"
    >
      <el-form ref="form" v-loading="isloading" :model="form" :rules="rules" :inline="true" label-width="250px">
        <el-row>
          <el-form-item label="业务流程名称" prop="processName">
            <el-input
              v-model="form.processName"
              placeholder="请输入业务流程名称"
              style="width: 204px"
            />
          </el-form-item>
          <el-form-item label="描述" prop="description">
            <el-input
              v-model="form.description"
              type="textarea"
              autosize
              style="width: 204px"
              placeholder="请输入描述"
            />
          </el-form-item>
          <!-- <el-form-item label="项目ID" prop="projectId">
            <el-input
              v-model="form.projectId"
              placeholder="请输入项目ID"
              style="width: 204px"
              disabled
            />
          </el-form-item>
          <el-form-item label="工作空间" prop="identifier">
            <el-input
              v-model="form.identifier"
              placeholder="请输入工作空间"
              style="width: 204px"
              disabled
            />
          </el-form-item> -->
          <div class="dialog-footer" style="text-align: center;">
            <el-button @click="closeDialog()">关闭</el-button>
            <el-button type="primary" @click="toAdd()">保存</el-button>
          </div>
        </el-row>
      </el-form>
    </el-dialog>
  </div>
</template>

<script>
import CRUD, { presenter, header, form, crud } from '@crud/crud'
import rrOperation from '@crud/RR.operation'
import crudOperation from '@crud/expand/golive/publish/CRUD.operation'
import pagination from '@crud/Pagination'
import publishBusinessApi from '@/api/golive/alibabaPublish/publishBusiness'
import publishTaskProcessApi from '@/api/golive/alibabaPublish/publishTaskProcess'

const defaultCrud = CRUD({
  title: '业务流程',
  url: '/api/deploy/business',
  crudMethod: { ...publishBusinessApi }
})
const defaultForm = {
  pkId: null,
  processName: '',
  description: ''
}
export default {
  components: { crudOperation, rrOperation, pagination },
  mixins: [presenter(defaultCrud), header(), form(defaultForm), crud()],
  data() {
    return {
      isloading: false,
      rules: {
        processName: [
          { required: true, message: '请输入业务流程名称', trigger: 'blur' }
        ]
      },
      permission: {
        add: ['admin', 'aliBusiness:add'],
        edit: ['aliBusiness:edit'],
        del: ['aliBusiness:del']
      },
      packFlag: false,
      textarea: ''
    }
  },
  methods: {
    async toAdd() {
      this.isloading = true
      const processForm = {}
      processForm.processType = 'CreateBusiness'
      const jsonDeployParam = {}
      jsonDeployParam.BusinessName = this.crud.form.processName
      jsonDeployParam.Description = this.crud.form.description
      processForm.deployParam = JSON.stringify(jsonDeployParam)
      console.log('processForm', processForm)
      await publishTaskProcessApi.create(processForm).then(res => {
        this.crud.form.pkId = res
        this.isloading = false
        this.closeDialog()
      }).catch(() => {
        this.$notify({ title: '告警', message: '新增业务流程失败！', type: 'warning' })
        this.isloading = false
      })
      this.isloading = false
    },
    closeDialog() {
      this.crud.cancelCU()
      this.crud.toQuery()
    }
  }
}
</script>

<style rel="stylesheet/scss" lang="scss" scoped>
</style>
